/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package amount;

import java.util.HashSet;
import score.Score;

/**
 *
 * @author Daniel Gribel
 */
public class LetterOrDigitAndSpecialCharAmount extends ComposedAmount {
    private int counterLetter;
    private int counterDigit;
    private int counterSpecialChar;
    
    public LetterOrDigitAndSpecialCharAmount(Score score, String name) {
        super(score, name);
        this.counterLetter = 0;
        this.counterDigit = 0;
        this.counterSpecialChar = 0;
    }
    
    @Override
    public void checkClauses(char character) {
        if(Character.isLetter(character))
            this.counterLetter++;
        if(Character.isDigit(character))
            this.counterDigit++;
        if(getSpecialChars().contains(character))
            this.counterSpecialChar++;
    }
    
    @Override
    public void consolidateScore() {
        if( (counterLetter > 0 || counterDigit > 0) && counterSpecialChar > 0)
            this.setCounter(1);
        else this.setCounter(0);
    }
    
    private static HashSet<Character> getSpecialChars() {
        HashSet<Character> symbols = new HashSet<Character>();
        symbols.add('!');
        symbols.add('@');
        symbols.add('#');
        symbols.add('$');
        symbols.add('%');
        symbols.add('^');
        symbols.add('&');
        symbols.add('*');
        symbols.add('?');
        symbols.add('_');
        symbols.add('~');
        return symbols;
    }
    
}
